<template>
	<view>
		<view class="news_item" @click="natetor(index)" v-for="(item,index) in list" :key="index">
			<image :src="item.img"></image>
			<view class="right">
				<view class="tit">
					{{item.title}}
				</view>
				<view class="info">
					<!-- <text>发表时间:{{item.date | formateDate}}</text> -->
					<text>发表时间:{{item.date}}</text>
					<text class="text_xx">浏览:{{item.count}}次</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: ['list'],
		//过滤器处理时间
		filters: {
			formateDate(date) {
				const nDate = new Data(date)
				const year = nDate.getFullYear()
				const month = nDate.getMonth().toString().padStart(2, 0) //不满足两位数加0在前面
				const day = nDate.getDay().toString().padStart(2, 0)
				return year + '年' + month + '月' + day + '日'
			}
		},
		methods: {
			natetor(index) {
				//触发父组件事件
				this.$emit('itemClick', index)
			}
		}

	}
</script>

<style lang="scss">
	.news_item {
		display: flex; //同一排下
		padding: 10rpx 20rpx;
		border-bottom: 1rpx solid $shop-color; //红色下横线

		image {
			min-width: 200rpx;
			max-width: 200rpx;
			height: 150rpx;
		}

		.right {
			margin-left: 15rpx; //间距
			display: flex; //布局
			flex-direction: column; //上下排列
			justify-content: space-between; //对齐方式

			.tit {
				font-size: 30rpx;
			}

			.info {
				font-size: 24rpx;

				text:nth-child(2) {
					margin-left: 30rpx;
				}
			}
		}

	}
</style>
